package com.jiuwu.spring.eshop.configuration;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 解决编码问题 setCharacterEncoding(gb2312)
 */

@Slf4j
@Configuration
@WebFilter(filterName = "charsetFilter", urlPatterns = "/*")
public class CharsetFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        log.info(request.getCharacterEncoding());
//        request.setCharacterEncoding("gb2312");
//        response.setCharacterEncoding("gb2312");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");

        chain.doFilter(request,response);
    }
}
